<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/18
 * Time: 14:25
 */

namespace Admin\Controller;

use Admin\Common\CommonController;

/**
 * Class BrandController
 * @package Admin\Controller
 * 品牌管理
 */

class BrandController extends CommonController
{
    /**
     * 品牌列表
     */
     public function  lists(){
       $brand=D('brand')->alldata();
//         dd($brand);
         $this->assign('brand',$brand);
       $this->display();
     }
    /**
     * 品牌添加
     */
    public function  add(){
        $bid=I('get.bid');
        if($bid){
            $olddata=M('brand')->where("bid=$bid")->find();
//            dd($olddata);
            $this->assign('olddata',$olddata);
        }
        if(IS_POST){
           if(notNull(I('bname'))) {
               $this->error('品牌名不能为空');die;
           }
            if(notNull(I('adduser'))) {
                $this->error('添加人不能为空');die;
            }
            if($bid){
                $_POST['bid']=$bid;
            }
            $_POST['aname']=session('aname');
            $_POST['addtime']=time();
           $res= D('brand')->store(I('post.'));
            $this->jump($res,'lists');
        }
        $this->display();
    }
    /**
     * 品牌删除
     */
    public function del(){
        $bid=I('get.bid');
//        dd($bid);die;
        $res=M('brand')->where("bid=$bid")->delete();
        if($res){
            $this->success('删除成功',U('lists'));die;
        }else{
            $this->error('删除失败');die;
        }
    }
}